#!/bin/bash

#云服务器根目录
CLOUD_ROOT="/var/camspace"
CLOUD_YUNHE_ROOT="${CLOUD_ROOT}/yunhe"
CLOUD_ANJU_ROOT="${CLOUD_ROOT}/anju"  
CLOUD_TANGKOU_ROOT="${CLOUD_ROOT}/tangkou" 

#内部服务器根目录
SERVER_ROOT="/home/zg/share" 
SERVER_YUNHE_ROOT="10.200.45.113:${SERVER_ROOT}" 
SERVER_ANJU_ROOT="10.200.35.172:${SERVER_ROOT}" 
SERVER_TANGKOU_ROOT="10.200.42.113:${SERVER_ROOT}" 

#线上运行的算法
yunhe_algo=("tarpa" "spray")
anju_algo=("tarpa")
tangkou_algo=("east_spray" "west_spray")


# 注意：
# ${#yunhe_algo[@]} 表示数组的长度 2
# ${!yunhe_algo[@]} 表示数组的索引列表 (0 1)
for i in "${!yunhe_algo[@]}";   
do   
	#创建目录
	dst=${CLOUD_YUNHE_ROOT}/${yunhe_algo[$i]}
	if [ ! -d ${dst} ]; then
		printf "Create dir => ${dst}\n"
		mkdir -p ${dst}
	fi
	umount ${dst}
	#挂载目录
	src=${SERVER_YUNHE_ROOT}/${yunhe_algo[$i]}
	mount -t nfs -o nolock ${src} ${dst}
	if [ $? -ne 0 ]; then
		echo "mount ${src} to ${dst} failed"
	fi  
done 

for i in "${!anju_algo[@]}";   
do   
	#创建目录
	dst=${CLOUD_ANJU_ROOT}/${anju_algo[$i]}
	if [ ! -d ${dst} ]; then
		printf "Create dir => ${dst}\n"
		mkdir -p ${dst}
	fi
	umount ${dst}
	#挂载目录
	src=${SERVER_ANJU_ROOT}/${anju_algo[$i]}
	mount -t nfs -o nolock ${src} ${dst}
	if [ $? -ne 0 ]; then
		echo "mount ${src} to ${dst} failed"
	fi  
done 

for i in "${!tangkou_algo[@]}";   
do   
	#创建目录
	dst=${CLOUD_TANGKOU_ROOT}/${tangkou_algo[$i]}
	if [ ! -d ${dst} ]; then
		printf "Create dir => ${dst}\n"
		mkdir -p ${dst}
	fi
	umount ${dst}
	#挂载目录
	src=${SERVER_TANGKOU_ROOT}/${tangkou_algo[$i]}
	mount -t nfs -o nolock ${src} ${dst}
	if [ $? -ne 0 ]; then
		echo "mount ${src} to ${dst} failed"
	fi  
done 

